package 字符串替换;

import java.util.*;

public class StringFormat {
    public String formatString(String A, int n, char[] arg, int m) {
        // write code here
        StringBuilder ret = new StringBuilder("");
        int k = 0;
        for (int i = 0; i < n; i++) {
            if (A.charAt(i) == '%') {
                if (i + 1 < n && A.charAt(i + 1) == 's') {
                    i++;
                    ret.append(arg[k++]);
                } else {
                    ret.append(A.charAt(i));
                }
            } else {
                ret.append(A.charAt(i));
            }
        }
        while (k < m) {
            ret.append(arg[k++]);
        }
        return ret.toString();
    }
}
